package com.tcc.fastline.Fragments;

import com.tcc.fastline.SessionManager;
import com.tcc.fastline.Domain.TipoUsuario;
import com.tcc.fastline.Helpers.AdapterHelper;
import com.tcc.fastline.Helpers.MenuHelper;
import com.tcc.fastline.Helpers.NavigationHelper;
import com.tcc.smartqueue.R;

import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class Inicio extends ConteudoFragment {

	private View _view;
	private Context context;
	private TextView txt;
	private GridView grid;
	private SessionManager session;

	@Override
	public ConteudoFragment newInstance() {

		Inicio newFragment = new Inicio();

		Bundle argumentsBundle = new Bundle();

		newFragment.setArguments(argumentsBundle);
		return newFragment;
	}

	@Override
	public ConteudoFragment newInstance(Bundle argumentsBundle) {
		return newInstance();
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.inicio, null);
		context = rootView.getContext();
		
		_view = rootView.findViewById(R.id.inicio_fragment);
		
		session = new SessionManager(context);
		session.checkLogin();
		String name = session.getNomeUsuario();

		txt = (TextView) rootView.findViewById(R.id.inicio_nomeUsuario);
		grid = (GridView) rootView.findViewById(R.id.gvInicio);
		
		txt.setText(name);

		grid.setAdapter(new AdapterHelper(context, session.getTipoUsuario()));
		grid.setOnItemClickListener(new OnItemClickListener() {
			
			public void onItemClick(AdapterView parent, View v, int position, long id) {
				//NavegarTela(((TextView) v.findViewById(R.id.Menu_Text)).getText().toString());
				NavegarTela(position);
			}

		});

		return rootView;
	}

	/*private void NavegarTela(String text) {
		String option = "menu_" + session.getTipoUsuario() + "_" + text.replace(' ', '_');
		MenuHelper.NavegarMenu(option.toUpperCase());
	}*/
	
	private void NavegarTela(int posicao) {
		String option = "menu_" + session.getTipoUsuario() + "_" + posicao;
		Log.e("MENU", option);
		MenuHelper.NavegarMenu(option.toUpperCase());
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceStateBundle) {
		super.onActivityCreated(savedInstanceStateBundle);
		_view.setVisibility(View.VISIBLE);

	}

}
